package com.fwtai.controller.web;

import com.fwtai.service.core.AreaService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 省市县区域控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2021-01-11 17:05:49
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/area")
public class AreaController{

  private final AreaService areaService;

  public AreaController(final AreaService areaService){
    this.areaService = areaService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('area_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.add(request),response);
  }

  /**添加代理区域*/
  @PreAuthorize("hasAuthority('area_btn_proxy')")
  @PostMapping("/addProxy")
  public void addProxy(final Long areaId,final Integer level,final HttpServletResponse response){
    ToolClient.responseJson(areaService.addProxy(areaId,level),response);
  }

  /**编辑*/
  @PreAuthorize("hasAuthority('area_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.edit(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('area_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.queryById(ToolClient.getFormData(request)),response);
  }

  /**删除-单行*/
  @PreAuthorize("hasAuthority('area_row_delById')")
  @PostMapping("/delById")
  public void delById(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.delById(ToolClient.getFormData(request)),response);
  }

  /**批量删除*/
  @PreAuthorize("hasAuthority('area_btn_delByKeys')")
  @PostMapping("/delByKeys")
  public void delByKeys(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.delByKeys(ToolClient.getFormData(request)),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('area_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.getListData(ToolClient.getFormData(request)),response);
  }
}